<?php
 include "counter.php";
 requirelogin();

 # Print list of possible values for "usage" in email
 function usagelist($name, $selection) {
       $somethingselected = 0;
       print '<select name="' . $name . '">';
       $usagelist = array("main", "old", "spare", "delete");
       foreach ($usagelist as $usage) {
          if ($selection == $usage) {
  	     print "<option value=\"$usage\" selected>$usage\n";
	     $somethingselected = 1;
	  } else {
  	     print "<option value=\"$usage\">$usage\n";
          }
       }
       if (!$somethingselected) {
          print "<option value=\"$selection\" selected>$selection\n";
       }
       print "</select>";

 }

 iamashowpage();


?>
<?php pagestart();
print "<html>\n";
pagehead("Email address edit");
?>
<BODY bgcolor="white">
<?php pagetop("Email address edit") ?>

<?php showmessage() ?>

<!-- Main content goes here -->
Note that this function is still somewhat experimental - please report
problems to the help address:<?php print
emailCloaking("help@counter.li.org") ?>
<p>
<?php
   $userid = currentuser();
   $query = mysql_query("select f_key, state, email.usage, level,
                        error, may_publish
                        from email
			where owner = $userid");
   if (!$query) {
      print ("MySQL error: " . mysql_errno() . ":" . mysql_error()
      . "<br>");
      die("Query for email addresses failed");
   }

?>
<form method=POST action="/cgi-bin/update-emails.cgi">
<table>
<tr><th>Email<th>Pub<th>Usage<th colspan=3>Error, if any
<?php
   while ($arr = mysql_fetch_array($query)) {
       print "<tr><td>";
       if ($arr[usage] == "main") {
          print "<b>";
       }
       print "<font size=+1>" . emailCloaking($arr["f_key"], 0) . "</font>";
       if ($arr[usage] == "main") {
          print "</b>";
       }
       $pubname = "\"pub-" . $arr[f_key] . "\"";
       if ($arr[may_publish] == "YES") {
         print "<td><input name=$pubname type=\"checkbox\" value=\"YES\" checked>";
       } else {
         print "<td><input name=$pubname type=\"checkbox\" value=\"YES\">";
       }
       print "<td>";
       usagelist("usage-" . $arr[f_key], $arr[usage]);       
       if ($arr[state] != "ok") {
          print "<td>";
          print $arr[state];
          print "<td>";
          print $arr[level];
	  print "<td>";
	  print $arr[error];

       }
       print "\n";
   }

?>
<tr><td>Add email:<br><input name="new-email" size=40
maxlength=256>
<td valign="bottom"><input name="new-may_publish" type="checkbox" value="YES">
<td valign="bottom"><?php usagelist("new-usage", "spare") ?>
</table>
<input type="submit">
<input type="reset">
</form>
<h2>Help with email addresses</h2>
You must have one "main" email - this is your contact with the
counter, and MUST be valid.<br>
"Spare" emails are emails that you can be found via, but are not
listed anywhere on the public site. These must be valid. The counter
staff may use one of these to contact you if your main email
bounces.<br>
"Old" emails are emails that you used to have, but no longer use. If
someone else registers with that email, they are allowed to take
it. (With all the other types, you own that email.)<br>
To delete an email, change its usage to "delete" and hit "submit".
<p>
Email with a mark on the "Pub" checkbox will be public, and shown on
your public page (if you have one). All others will never be shown to
anyone, but they may be used to search for you.
<?php pagebottom() ?>
</body>
</html>


